package RenameBean;

import MethodAnnotations.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Author quan
 * @Description 给@Bean添加参数
 * @Date 2023/7/13 9:54
 */

@Configuration
public class a03_AddParamsToBean {
    //常规写法
//    @Bean(name= {"aaa"})
//    public AddParams.User user(){
//        AddParams.User user = new AddParams.User();
//        user.setName("小星星");
//        user.setAge(1);
//        return user;
//    }
    //给@Bean添加参数
    @Bean
    public String reqName(){
        return "小星星";
    }
    @Bean
    public Integer reqAge(){
        return 11;
    }

    @Bean
    public Integer reqAge1(){
        return 22;
    }
    @Bean("aaa")
    public User user(String name,Integer reqAge1){
        User user = new User();
        user.setName(name);
        user.setAge(reqAge1);
        return user;
    }
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
        User user = (User) context.getBean("aaa");
        System.out.println(user.getAge());
        System.out.println(user.getName());
    }
}
